<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link href="/resource/css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="/resource/js/bootstrap.js"></script>
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
</head>
<body>
<form action="" method="post">
<div class="row" style="margin-top: 25px">
<!-- 	<div class="col-md-2"></div>-->	
	<!-- <div class="col-md-8"> -->
	<!-- 拿去所有的品牌 -->
		<c:forEach items="${list }" var="l">
		 <div class="card" style="width: 20rem;">
  			<img src="${l.pic }" class="card-img-top" alt="...">
 			 <div class="card-body">
   			<a class="JavaScript:void(0)" onclick="brand(${l.bid})"><h5 class="card-title">${l.bname }</h5></a>
    		<p class="card-text">${l.describe }</p>
    		<p class="card-text">${l.price }</p>
<%--     		<a href="shopping?id=${l.id }+?bid=${l.bid}" class="btn btn-primary">加入购物车</a>--%>
    		<button onclick="shopping(${l.id })">加入购物车</button>
  			</div>
		</div>
		</c:forEach>
	<!-- </div> -->
</div>
	<div id="a" class="row" style="margin-top: 25px"></div>
</form>
</body>
<script type="text/javascript">
	function brand(id){
		alert(id)
		//拿到品牌的id
		//知道这个品牌下的所有商品
		 /* $.post("selectGoods",{"id":id},function(){ */
			$("#a").load("/selectGoods?id="+id);
		/* })  */
	}
	function shopping(id){
		alert(id);
		$.post("addShopping",{"id":id},function(obj){
			alert(obj)
			if(obj>0){
				alert("成功加入购物车!!!")
				location.href="redirect:/";
			}else{
				alert("加入购物车失败,请重新加入!!!")
			}
		},"json")
	}
</script>
</html>